package database_interaction;

/**
 * @file SQLQuery.java
 * @version 0.1
 * @author James Dibble 10009689
 */
public abstract class SQLQuery {
    // <editor-fold defaultstate="collapsed" desc="Attributes">
    private QueryType _type;
    private String _table;
    public ParameterList _parms;
    private String _filter;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Constructors">
    public SQLQuery(QueryType type, String table) {
        this._type = type;
        this._table = table;
        this._parms = new ParameterList();
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Methods">
    public abstract String getQueryString() throws JDBCException;
        
    public String getTable(){
        return this._table;
    }
        
    public QueryType getQueryType(){
        return this._type;
    }
    
    public void addParameter(Parameter parm) throws JDBCException{
        if(this._type == QueryType.SELECT)
            throw new JDBCException("Select querys can not take parameters.");
        this._parms.addParameter(parm);
    }
    
    public void addParameter(Parameter parm, String columnName) throws JDBCException{
        if(this._type == QueryType.SELECT)
            throw new JDBCException("Select querys can not take parameters.");
        this._parms.addParameter(parm);
        this._parms.addColumn(columnName);
    }
    
    public void addColumn(String columnName){
        this._parms.addColumn(columnName);
    }
    
    public String getFilter() throws JDBCException{
        if(this._type == QueryType.INSERT)
            throw new JDBCException("Insert queries do no take filters.");
        return this._filter;
    }
    
    public void setFilter(String filter) throws JDBCException{
        if(this._type == QueryType.INSERT)
            throw new JDBCException("Insert queries do no take filters.");
        this._filter = filter;
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="Enums">
    public enum QueryType{
        INSERT,
        SELECT,
        DELETE,
        UPDATE//,
        //STORED_PROCEDURE
    }
    // </editor-fold>
}